<template>
    <div>
        <el-form ref="formRef" :inline="true" :model="form" class="search-form bg-bg_color w-[99/100] pl-8 pt-[12px]">
            <el-form-item label="名称：" prop="name">
                <el-input v-model="form.name" placeholder="请输入名称" clearable class="!w-[200px]" />
            </el-form-item>
            <el-form-item label="类型：" prop="type">
                <el-select v-model="form.type" clearable>
                    <el-option label="循环触发" :value="0" />
                    <el-option label="定时触发" :value="1" />
                    <el-option label="指定时间触发" :value="2" />
                </el-select>
            </el-form-item>
            <el-form-item label="状态：" prop="status">
                <el-select v-model="form.status" clearable>
                    <el-option label="全部" :value="''" />
                    <el-option label="启用" :value="1" />
                    <el-option label="禁用" :value="0" />
                </el-select>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" :icon="useRenderIcon(Search)" :loading="loading" @click="onSearch">
                    搜索
                </el-button>
                <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
                    重置
                </el-button>
            </el-form-item>
        </el-form>


        <PureTableBar title="巡检路线" :columns="columns" @refresh="onSearch">
            <template #buttons>
                <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="openDialog()">
                    新增路线
                </el-button>
            </template>
            <template v-slot="{ size, dynamicColumns }">
                <pure-table ref="tableRef" adaptive align-whole="center" row-key="Id" showOverflowTooltip
                    table-layout="auto" :loading="loading" :size="size" :data="dataList" :columns="dynamicColumns"
                    :pagination="pagination" :paginationSmall="size === 'small' ? true : false" :header-cell-style="{
                        background: 'var(--el-fill-color-light)',
                        color: 'var(--el-text-color-primary)'
                    }" @page-size-change="handleSizeChange" @page-current-change="handleCurrentChange">
                    <template #operation="{ row }">
                        <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
                            @click="openDialog('编辑', row)">
                            编辑
                        </el-button>
                        <el-button class="reset-margin" link type="danger" :size="size"
                            :icon="useRenderIcon(outlineDelete)" @click="handleDelete(row)">
                            删除
                        </el-button>
                    </template>
                </pure-table>
            </template>
        </PureTableBar>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import { useDept } from "./utils/hook";
import { dialogStoreHook } from "@/store/modules/dialog";
const dialogStatus = dialogStoreHook();

// iconify-icons
import AddFill from "@iconify-icons/ri/add-circle-line";
import EditPen from "@iconify-icons/ep/edit-pen";
import outlineDelete from '@iconify-icons/ic/outline-delete';
import Search from "@iconify-icons/ep/search";
import Refresh from "@iconify-icons/ep/refresh";
import { log } from "node:console";

const formRef = ref();

// onMounted(() => {
//     dialogStatus.setSiteList();
//     dialogStatus.setStationSelect();
// })

const {
    columns,
    loading,
    dataList,
    openDialog,
    handleDelete,
    form,
    onSearch,
    resetForm,
    pagination,
    handleSizeChange,
    handleCurrentChange
} = useDept();

</script>

<style scoped></style>